package com.hotel.controllers;

import com.github.pagehelper.PageInfo;
import com.hotel.entitys.*;
import com.hotel.services.VipService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags="vip客户信息接口")//tags:说明信息
public class VipController {
    @Autowired
    private VipService vipService;

    @ApiOperation(
            value = "查询所有vip客户",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/vip")
    public RestPOJO getAllStaff(Integer currentPage, Integer pageSize, String keyword){
        RestPOJO restPOJO = new RestPOJO();
        PageInfo<Vip> pageInfo = vipService.getAllVip(currentPage,pageSize,keyword);
        if (pageInfo!=null && pageInfo.getList().size()>0){
            restPOJO.setMessage("查询Vip数据成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(pageInfo);
        }else {
            restPOJO.setMessage("查询Vip数据失败");
            restPOJO.setStatus(1001);
            restPOJO.setData(pageInfo);
        }
        return restPOJO;
    }
    @ApiOperation(
            value = "增加vip客户",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/vip/add")
    public RestPOJO addVip(@RequestBody Vip vip){
        RestPOJO restPOJO = new RestPOJO();
        int count = vipService.addVip(vip);
        if (count > 0){
            restPOJO.setMessage("增加Vip成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("增加Vip失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "修改vip客户等级",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )


    @GetMapping("/vip/{id}")
    public RestPOJO getSingleVip(@PathVariable("id") Integer vip_id){
        RestPOJO restPOJO = new RestPOJO();
        Vip vip = vipService.getVipById(vip_id);
        Map<String,Object> map = new HashMap<String, Object>();
        map.put("vip",vip);
        restPOJO.setData(map);
        return restPOJO;
    }
    @ApiOperation(
            value = "修改vip客户",
            httpMethod = "PUT",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PutMapping("/vip")
    public RestPOJO updateVip(@RequestBody Vip vip){
        RestPOJO restPOJO = new RestPOJO();
        int count = vipService.changeVip(vip);
        if (count > 0){
            restPOJO.setMessage("Vip员工修改成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("Vip员工修改失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "删除vip客户",
            httpMethod = "DELETE",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @DeleteMapping("/vip/{id}")
    public RestPOJO deleteSingleVip(@PathVariable("id") Integer vip_id){
        RestPOJO restPOJO = new RestPOJO();
        int count = vipService.deleteOneVip(vip_id);
        if (count > 0){
            restPOJO.setMessage("删除Vip成功");
            restPOJO.setStatus(1000);
        } else {
            restPOJO.setMessage("删除Vip失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }

    @ApiOperation(
            value = "批量删除vip客户",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/vip/delAll")
    public RestPOJO deleteMultiStaff(@RequestBody Object[] ids){
        RestPOJO restPOJO = new RestPOJO();
        int count = vipService.deleteMultiVip(ids);
        if (count > 0){
            restPOJO.setMessage("批量删除员工Vip");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("批量删除员工Vip");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }
    @ApiOperation(
            value = "通过会员电话查询单个会员信息",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/checkin/vip/{tel}")
    public RestPOJO getVip(@PathVariable("tel") String telephone){
        RestPOJO restPOJO = new RestPOJO();
        Vip vip = vipService.getVip(telephone);
        if(vip != null){
            restPOJO.setMessage("查询单个Vip数据成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(vip);
        }else {
            restPOJO.setMessage("查询单个Vip数据失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }
}
